<?php

namespace App\Hospital\Controllers;

use App\Hospital\Repositories\Interview;
use Dcat\Admin\Admin;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class InterviewController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Interview(['user','family','familyPreg']), function (Grid $grid) {
            $grid->model()->where('hospital_id',Admin::user()->hospital_id)->orderBy('created_at','desc');
            $grid->column('family.name','孕产妇姓名');
            $grid->column('user.phone','联系电话');

            $grid->column('type')->using(\App\Models\Interview::$typeTxt);
            $grid->column('pt_hospital');
            $grid->column('pt_date');
            $grid->column('prenatal')->using(\App\Models\Interview::$prenatalTxt);

            $grid->column('pt_value')->using(\App\Models\Interview::$ptValueTxt);
            $grid->column('created_at');

            $grid->disableCreateButton();
            $grid->disableDeleteButton();
            $grid->disableEditButton();
            $grid->disableQuickEditButton();
            $grid->disableRowSelector();
            $grid->showColumnSelector();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->expand(false);
                $filter->equal('family.name','孕产妇姓名');
                $filter->equal('user.phone','联系电话');
                $filter->equal('type')->select(\App\Models\Interview::$typeTxt);
                $filter->equal('prenatal')->select(\App\Models\Interview::$prenatalTxt);
                $filter->equal('pt_value')->select(\App\Models\Interview::$ptValueTxt);

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Interview(['user','family','familyPreg']), function (Show $show) {
            $show->field('family.name','孕产妇姓名');
            $show->field('user.phone','联系电话');
            $show->field('pt_hospital');
            $show->field('pt_date');
            $show->field('prenatal')->using(\App\Models\Interview::$prenatalTxt);
            $show->field('childbirth_hospital');
            $show->field('childbirth_date');
            $show->field('childbirth_type')->using(\App\Models\Interview::$ctypeTxt);
            $show->field('pt_value')->using(\App\Models\Interview::$ptValueTxt);
            $show->field('type')->using(\App\Models\Interview::$typeTxt);

            $show->field('created_at');
            $show->panel()
                ->tools(function ($tools) {
                    $tools->disableEdit();
                    $tools->disableDelete();
                });
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Interview(), function (Form $form) {
            $form->display('id');
            $form->text('prenatal_test');
            $form->text('hospital_id');
            $form->text('pt_hospital');
            $form->text('pt_date');
            $form->text('prenatal');
            $form->text('childbirth_hospital');
            $form->text('childbirth_date');
            $form->text('childbirth_type');
            $form->text('pt_value');
            $form->text('type');
            $form->text('user_id');
            $form->text('family_id');
            $form->text('family_pregn_id');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
